package com.anpxd.erpad.adapter

import android.annotation.SuppressLint
import android.support.v4.content.ContextCompat
import android.widget.ImageView
import com.anpxd.erpad.R
import com.anpxd.erpad.bean.BrandItem
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.gg.image.config.GlideApp

/**
 *  Creator : GG
 *  Time    : 2017/11/17
 *  Mail    : gg.jin.yu@gmail.com
 *  Explain :
 */
class BrandAdapter(data: ArrayList<BrandItem>) : BaseMultiItemQuickAdapter<BrandItem, BaseViewHolder>(data) {

    init {
        addItemType(BrandItem.TITLE, R.layout.item_header)
        addItemType(BrandItem.ITEM, R.layout.item_brand)
    }

    @SuppressLint("ResourceAsColor")
    override fun convert(helper: BaseViewHolder?, item: BrandItem) {
        when (helper?.itemViewType) {
            BrandItem.TITLE -> helper.setText(R.id.title_text, item.title)

            BrandItem.ITEM -> {
                val imageView = helper.getView<ImageView>(R.id.logo)
                GlideApp.with(mContext).load(item.brand?.brandLogo).into(imageView)
                helper.setText(R.id.name, item.brand?.brandName)
                if (item.choose) {
                    helper.setTextColor(R.id.name, ContextCompat.getColor(mContext, R.color.text_orange))
                    helper.setVisible(R.id.check_mark, true)
                } else {
                    helper.setTextColor(R.id.name, ContextCompat.getColor(mContext, R.color.text_black))
                    helper.setVisible(R.id.check_mark, false)
                }

            }
        }
    }
}